// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

// Let VC++ know we are compiling for WinXP and up.  This let's us use
// API functions specific to WinXP (e.g., WM_INPUT API).
#ifndef _WIN32_WINNT
#define _WIN32_WINNT   0x0600 // Vista
#endif

 
// Enable extra D3D debugging in debug builds if using the debug DirectX runtime.  
// This makes D3D objects work well in the debugger watch window, but slows down 
// performance slightly.
#if defined(DEBUG) || defined(_DEBUG)
	#ifndef D3D_DEBUG_INFO
	#define D3D_DEBUG_INFO
	#endif
#endif

//#if defined(DEBUG) || defined(_DEBUG)
//#define _CRTDBG_MAP_ALLOC
//#include <crtdbg.h>
//#endif


#include <stdio.h>
#include <tchar.h>
#include <string>
#include <sstream>
#include <map>
#include <vector>
#include <cassert>
#include <fstream>
#include <Windows.h>

#include <new>
#include <cstdlib>


#include <d3d11.h>
#include <d3dx11.h>
#include <dxerr.h>

#include <xnamath.h>

#if defined(DEBUG) | defined(_DEBUG)
//#include "mmgr.h"
#endif 

#include "Logger.h"
#define LOG(x) mcore::Logger::get().log(x)

#if defined(DEBUG) | defined(_DEBUG)
	#ifndef HR
	#define HR(x)                                              \
	{                                                          \
		HRESULT hr = (x);                                      \
		if(FAILED(hr))                                         \
		{                                                      \
			DXTrace(__FILE__, (DWORD)__LINE__, hr, #x, true); \
		}                                                      \
	}
	#endif

#else
	#ifndef HR
	#define HR(x) (x)
	#endif
#endif 

#define ReleaseCOM(x) { if(x){ x->Release();x = 0; } }


typedef unsigned int uint;
typedef unsigned char byte;
typedef unsigned short ushort;

#define OVERRIDE_NEW_DELETE_WITH_ALIGNMENT(alignment)		\
	void* operator new (size_t size)						\
	{														\
		void * p = _aligned_malloc(size, alignment);		\
		if (p == 0) LOG("ACHTUNG!!! OUT OF MEMORY!!!");		\
		return p;											\
	}														\
	void operator delete (void *p)							\
	{														\
		_aligned_free(p);									\
	}

const float INFINITY = FLT_MAX;
const float PI       = 3.14159265358979323f;
const float MATH_EPS = 0.0001f;

typedef XMFLOAT4 XMCOLOR4F;
typedef XMFLOAT3 XMCOLOR3F;

#define TODXCOLOR(color) (*(D3DXCOLOR*)&color) // for XMCOLOR4F only!!!
#define XMCOLOR4F_TO_3F(color) (XMCOLOR3F(color.x, color.y, color.z))

namespace ColorA
{
	const XMVECTOR WHITE = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f);
	const XMVECTOR BLACK = XMVectorSet(0.0f, 0.0f, 0.0f, 1.0f);
	const XMVECTOR RED = XMVectorSet(1.0f, 0.0f, 0.0f, 1.0f);
	const XMVECTOR GREEN = XMVectorSet(0.0f, 1.0f, 0.0f, 1.0f);
	const XMVECTOR BLUE = XMVectorSet(0.0f, 0.0f, 1.0f, 1.0f);
}

#define OVERRIDE_NEW_DELETE_WITH_ALIGNMENT(alignment)           \
	void* operator new (size_t size)                                                \
{                                                                                                               \
	void * p = _aligned_malloc(size, alignment);            \
	if (p == 0) LOG("ACHTUNG!!! OUT OF MEMORY!!!");         \
	return p;                                                                                       \
}                                                                                                               \
	void operator delete (void *p)                                                  \
{                                                                                                               \
	_aligned_free(p);                                                                       \
}


// TODO: reference additional headers your program requires here
